package com.vint.lintcode;

/**
 * Copyright (C) 2017, Xiaomi Inc. All rights reserved.
 * Created by vint @ 2017/11/5.
 * in leetcode
 */
public class Lintcode382 {
	public static int triangleCount(int[] S) {
		if(S.length<3)return 0;
		int sum = 0;
		for(int i=0;i<S.length;i++){
			for(int j=i+1; j<S.length;j++){
				for(int k=j+1;k<S.length;k++){
					if(isTriangle(S[i],S[j],S[k]))sum++;
				}
			}
		}
		return sum;

	}
	public static boolean isTriangle(int a, int b, int c){
		if(a<=0||b<=0||c<=0)return false;
		int max = Math.max(a,Math.max(b,c));
		if(max==a)return b+c>a;
		if(max==b)return a+c>b;
		if(max==c)return b+a>c;
		return false;
	}
	public static void main(String[] args) {
		int[] S1 = {4,4,4,4};
		int[] S2 = {3,4,6,7};
		System.out.println(triangleCount(S1));
		System.out.println(triangleCount(S2));
	}
}
